package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.VideoComment;
import com.juyu.miliao.api.domain.vo.VideoCommentVO;
import com.juyu.miliao.api.service.VideoCommentService;
import com.juyu.miliao.api.validator.common.Save;
import com.juyu.miliao.common.domain.BaseQuery;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 视频评论
 *
 * @author jh
 * 10:50
 */
@RestController
@RequestMapping(value = "/video")
public class VideoCommentController {

    @Resource
    private VideoCommentService videoCommentService;

    /**
     * 列表
     *
     * @param videoId   videoId
     * @param baseQuery baseQuery
     * @return List<VideoComment>
     */
    @GetMapping(value = "/comment/{videoId}/{pageNum}-{pageSize}")
    public VideoCommentVO list(BaseQuery baseQuery,
                               @PathVariable("videoId") Long videoId,
                               @PathVariable("pageNum") String pageNum,
                               @PathVariable("pageSize") String pageSize) {
        return videoCommentService.list(videoId, baseQuery);
    }

    /**
     * 保存评论
     *
     * @param token        token
     * @param videoComment videoComment
     *                     // * @param videoId      videoId
     */
    @PostMapping(value = "/comment")
    public void save(Authentication token,
                     @Validated(value = Save.class) VideoComment videoComment) {
        Subject subject = (Subject) token.getPrincipal();
        Long userId = subject.getId();
        videoCommentService.save(userId, videoComment);
    }

}


